#!/usr/bin/python

from twisted.internet import app
from twisted.python import log
from twisted.protocols import portforward
from twisted.tap.portforward import Options

class LoggingProxyClient(portforward.ProxyClient):
    def dataReceived(self, data):
        #log.msg('server sent: ' + repr(data))
        portforward.ProxyClient.dataReceived(self, data)

class LoggingProxyClientFactory(portforward.ProxyClientFactory):
    protocol = LoggingProxyClient

class LoggingProxyServer(portforward.ProxyServer):
    clientProtocolFactory = LoggingProxyClientFactory

    def connectionMade(self):
        log.msg('Client Connect on %s' % self.transport.getPeer() )
        portforward.ProxyServer.connectionMade(self)

    def dataReceived(self, data):
        portforward.ProxyServer.dataReceived(self, data)

    def connectionLost(self, reason):
        log.msg('Client Lost on : %s reason is  %s' % (self.transport.getPeer(),reason.getErrorMessage()))

class LoggingProxyFactory(portforward.ProxyFactory):
    protocol = LoggingProxyServer

application = app.Application('LoggingPortForward')
application.listenTCP(60308, LoggingProxyFactory('211.99.44.215', 60306))
